<?php
	defined('_JEXEC') or die('Restricted access');
	require_once(CUTEENGINE_BASE_FIELD_PATH."base_field_class.php");
    
	//
    // t_field_overlap
    //
	class t_field_overlap extends t_base_field
	{
        
        // property declaration
		// protected
		protected $tags_names_list = array();
        // O
        //protected $value_db_fields = array();
		protected $close_button_tag = null;
        protected $open_button_tag = null;
		protected $overlap_tag = null;
		protected $overlap_content_tag = null;
		// M 
		protected $message_tag = null;
      

        // property declaration
		// public
		// C
		const closing_method_type_button = 1;
		const closing_method_type_dbclick_event = 2;
		const closing_method_type_select_event = 3;
		const closing_method_type_last = 4;
		// L
		const language_position_open_button_label = 1;
		const language_position_closing_button_label = 2;
		const language_position_last = 3;
		
		// P
		// POSTFIX
		const postfix_close_button_tag_name = "_close_button";
		const postfix_open_button_tag_name = "_open_button";
		const postfix_message_tag_name = "_msg";
		const postfix_overlap = "_overlap";
		const postfix_overlap_content = "_overlap_content";
		// PROPER_PROPERTIES
		const proper_properties_position_bound_component_id = 1;
        const proper_properties_position_closing_method_type = 2;
		const proper_properties_position_return_field_name = 3;       
        const proper_properties_position_last = 4;
        // method declaration
    	// protected

		// A
        protected function adds_check_value_method()
        {
            global $g_javascript_namespace;
         	/*$g_javascript_namespace->header_script_generator->add_method_to_a_class_with_content(
				get_class($this),"check_value","a_name","
    var local_name = a_name;
	if (a_name == undefined)
		local_name = this.name;                
    var local_value = this.html_tag(local_name).value.trim();            
    var local_msg_tag = this.html_tag(local_name+'_msg');           
	var local_return = true;
    if (this.can_not_be_empty)
    {
		local_return = (this.html_tag(this.name).value.trim() != '');
		
    }
    if (!local_return)
        local_msg_tag.innerHTML = this.can_not_be_empty_msg;
    else
        local_msg_tag.innerHTML = '';    
	return local_return;
    "); */
        }
        // G
		
		protected function get_field_event_script($a_event_type,$a_argouments)
        {			
			$local_return = '';
			return $local_return;
		}
		public function get_included_in_html_structure($a_name,$a_display,$a_key_tag_name,$a_current_row_no)
		{
			return '';
		}
		public function get_included_in_html_structure_no_edit_mode($a_name,$a_display,$a_key_tag_name,$a_current_row_no)
		{
			
			global $g_cuteengine;
			//parent::get_included_in_html_structure($a_name);
			if ($a_current_row_no == t_field_grid::row_action_name_MUACT)
				return '';
			if ($a_display)
			{
				$this->main_tag->add_style_property('display','');
			}
			else
			{
				$this->main_tag->add_style_property('display','none');
			}	
			$this->tags_names_list[$a_name] = $a_key_tag_name;
			//echo "a_current_row_no: $a_current_row_no - a_name: $a_name - a_key_tag_name: $a_key_tag_name<br>";
			//print_r($this->main_tag);			
			//if ($a_current_row_no == 'ins')
			//{
				
				//$local_bound_component_id = $this->proper_properties_array[self::proper_properties_position_bound_component_id];
				//echo "local_bound_component_id: ". $local_bound_component_id."<br>";
				//$local_child_component = $g_cuteengine->get_cuteengine_component_by_id($local_bound_component_id)->page_component;
				//print_r($local_child_component);
				
				//echo "local_child_component->name: $local_child_component->name <br>";
				//$this->overlap_tag->add_child_at_bottom($local_child_component->get_start_field_name()->main_tag);
			//}
			//echo $this->main_tag->generate_html_code_with_new_name($a_name);
			return $this->main_tag->generate_html_code_with_new_name($a_name);
		}		
static function get_help_proper_property($a_index)
		{
			$local_return = 'NO HELP AVAILABLE';
			/*switch ($a_index) 
            {
                case self::proper_properties_position_:
					$local_return = '';
				break;                
			}*/
			return $local_return;
		}
        static function get_default_proper_property($a_index)
		{
			$local_return = '';
			/*switch ($a_index) 
            {
                case self::proper_properties_position_:
					$local_return = 'TRUE';
				break;                
			}*/
			return $local_return;
		}
		protected function get_proper_properties_position_last()      
		{
            return self::proper_properties_position_last;
        }
		
        // method declaration
    	// public
        public function __construct($a_parent_part,$a_common_properties_str, $a_proper_properties_str)
		{
			global $g_ambient_namespace;
			global $g_javascript_namespace;
            parent::__construct($a_parent_part,$a_common_properties_str, $a_proper_properties_str);
			$local_file_name = CUTEENGINE_CUSTOM_LANGUAGES_PATH.$g_ambient_namespace->language.DIRECTORY_SEPARATOR.$this->name."_lang.php";
            //echo "local_file_name: $local_file_name<br>";
			// LANGUAGES
            if (file_exists($local_file_name))
                $g_ambient_namespace->load_custom_language($this,$this->name);

			
		}

		// C
		public function create_javascript_initialization_component()
		{
			global $g_cuteengine;
			global $g_javascript_namespace;
			//C
			$g_javascript_namespace->header_script_generator->add_method_to_a_class_with_content(
				get_class($this),'close_overlap','event'," 
	if (event.nodeName != undefined)			
		var local_target = event;
	else 
		var local_target = event.target ? event.target : event.srcElement;			
    set_tag_style_property(['display'],['none'],local_target.parentNode ,true);
	");
			// O
			$g_javascript_namespace->header_script_generator->add_method_to_a_class_with_content(
				get_class($this),'open_overlap','event'," 
    var local_target = event.target ? event.target : event.srcElement;
	var local_tag = document.getElementById(this.get_bound_component_tag_name());
	var local_content = local_target.nextSibling.firstChild;
	if ((local_tag.parentNode.nextSibling != undefined) && (local_tag.parentNode.nextSibling.nextSibling != undefined))
	{
		this.close_overlap(local_tag.parentNode.nextSibling.nextSibling);
	}
	local_tag = local_tag.parentNode.removeChild(local_tag);
	local_content.appendChild(local_tag); 
	set_tag_style_property(['display'],[''],local_tag ,true);
	set_tag_style_property(['display'],[''],local_target.nextSibling ,true);
	");	

	}	
        
		public function create_tags_structure()
        {
            global $g_javascript_namespace;
            //echo __METHOD__."<BR>";
            parent::create_tags_structure();
			// proprierties

            // STYLE
			// tags    
            $local_name = $this->common_properties_array[t_base_field::common_properties_position_per_field_name];
			$local_current_tag = parent::add_tag(t_base_tag_type::btt_div,$local_name);
			$this->main_tag = $local_current_tag;
            // open_button tag
			$local_open_button_label = addslashes($this->lang[self::language_position_open_button_label]);
            $local_current_tag = $this->main_tag->create_and_add_child_at_bottom(t_base_tag_type::btt_button,$local_name . self::postfix_open_button_tag_name);
			$local_current_tag->set_text_to_include($local_open_button_label);
			$local_current_tag->add_property("onclick",t_cuteengine::javascript_instance_name.".".$this->name.".open_overlap(event)");
            $this->open_button_tag = $local_current_tag;
			// overlap_form tag
            $local_current_tag = $this->main_tag->create_and_add_child_at_bottom(t_base_tag_type::btt_div,
                $local_name. self::postfix_overlap);
			$this->overlap_tag = $local_current_tag;
			$this->overlap_tag->add_style_property('display','none');
			//$this->parent_component->set_to_childs_components_tag($this->overlap_tag);
			$this->overlap_content_tag = $this->overlap_tag->create_and_add_child_at_bottom(t_base_tag_type::btt_div,
                $local_name. self::postfix_overlap_content);
			// message tag
			$local_current_tag = $this->overlap_tag->create_and_add_child_at_bottom(t_base_tag_type::btt_label,$local_name . self::postfix_message_tag_name);
            $this->message_tag = $local_current_tag;
			$this->message_tag->class_name = t_base_field::error_msg_class_name;	
            // close_button tag
			$local_close_button_label = addslashes($this->lang[self::language_position_closing_button_label]);
            $local_current_tag = $this->overlap_tag->create_and_add_child_at_bottom(t_base_tag_type::btt_button,
				$local_name . self::postfix_close_button_tag_name);
			$local_current_tag->set_text_to_include($local_close_button_label);
			$local_current_tag->add_property("onclick",t_cuteengine::javascript_instance_name.".".$this->name.".close_overlap(event)");
            $this->close_button_tag = $local_current_tag;
			//
            $this->default_start_tag = $this->open_button_tag;
            $this->default_result_tag = $this->close_button_tag;
            // method
            //$this->adds_check_value_method();

            
            
        }
        // G
		public function get_language_position_last()
        {
            return self::language_position_last;
        }
		public function get_result_action_script($a_event_type,$parent_event_type,
            $a_parameter,$a_content_loader_result)
		{
            return '';
        }		
		// F
		public function finalize_creation_field()
        {
			global $g_cuteengine;
			global $g_javascript_namespace;
			parent::finalize_creation_field();			
			// G
			$local_bound_component_id = $this->proper_properties_array[self::proper_properties_position_bound_component_id];
			//echo "local_bound_component_id: ". $local_bound_component_id."<br>";
			$local_bound_component_tag_name = $g_cuteengine->get_cuteengine_component_by_id($local_bound_component_id)->page_component;
			//print_r($local_bound_component_tag_name);	
			//echo "local_bound_component_tag_name->name: $local_bound_component_tag_name->name <br>";
			$local_tag_name = $local_bound_component_tag_name->main_tag->name;

			$g_javascript_namespace->header_script_generator->add_method_to_a_class_with_content(
				get_class($this),'get_bound_component_tag_name',''," 
    if (this.name == '".$this->name."')
	{
		return '$local_tag_name'; 
	}
	");	
			$local_content = $g_javascript_namespace->header_script_generator->add_content_to_a_method(
				get_class($this), t_header_script_generator::create_label,"
		set_tag_style_property(['display'],['none'],this.get_bound_component_tag_name() ,true);");
		
		}		
	
		

		// I
		public function initialize_field_event($a_event_type)
        {			
			
		}
        
       

		

    }
?>    